package model.financial;

import java.util.ArrayList;
import java.util.List;

import model.AbstractGetDateFromString;
import model.person.Person;

public class FinancialManagement {
	private List<Bill> bills = new ArrayList<Bill>();

	public FinancialManagement() {

	}

	public String getBillData() {
		String data = "\nBills in the system:";
		for (Bill b : bills) {
			data += "\nName: " + b.getPerson().getFirstName() + " "
					+ b.getPerson().getLastname();
			data += "\nAmount: "
					+ b.getAmount()
					+ "\n"
					+ AbstractGetDateFromString.getDateFromString(b
							.getTimestamp());
			data += "\nStatus: " + b.getStateString();
		}
		return data;
	}

	public void addBill(int amount, String date, Person person) {
		bills.add(new Bill(amount, date, person));
	}

	public void handleBill(Person person, String date) {
		for (Bill b : bills) {
			if (b.getPerson().equals(person)) {
				if (b.getTimestamp().equals(date)) {
					try {
						b.handleBill();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

	public void archiveBill(Person person, String date) {
		for (Bill b : bills) {
			if (b.getPerson().equals(person)) {
				if (b.getTimestamp().equals(date)) {
					try {
						b.archiveBill();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

}
